import { IBizLabTemplate } from "@ibizlab/template";
import { handleJudgmentExecute } from "../../util";

/**
 * 是否存在某类型部件 {{hasCtrl ctrls 'form'}} {{hasCtrl ctrls 'grid'}}
 *
 * @export
 * @class HasCtrl
 */
export class HasCtrl {
  /**
   * Creates an instance of HasCtrl.
   * @param {IBizLabTemplate} template
   * @memberof HasCtrl
   */
  constructor(template: IBizLabTemplate) {
    template.engine.registerHelper("hasCtrl", (...args: unknown[]) => {
      const ctrls = args[0] as any[] || [];
      const controlType = args[1] as string;
      const options = args[2] as any;
      const result = ctrls.findIndex((item: any) => item.controlType === controlType) !== -1;
      return handleJudgmentExecute(this, result, options);
    });
  }
}
